package binarysearch.test240;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/7/13 10:37
 */
public class Solution1 {

    // 搜索二维矩阵
    public boolean searchMatrix(int[][] matrix, int target) {
        if(matrix == null || matrix.length == 0 || matrix[0].length == 0) return false;
        int m = matrix.length, n = matrix[0].length;
        int r = m - 1, c = 0;
        while(r >= 0 && c >= 0 && r < m && c < n){
            if(matrix[r][c] == target) return true;
            else if(matrix[r][c] < target) c++;
            else r--;
        }
        return false;
    }
}
